﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Windows.Forms;
using System.IO;

namespace CalemShop
{
    public class RuntimeData
    {
        public static Hashtable config;
        public static bool IsLogin = false;
        const string mysqlDump = @"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe";

        public static string GetDataDir()
        {
            string dirPath = Application.ExecutablePath;
            dirPath = Path.GetDirectoryName(dirPath);
            DateTime d = DateTime.Now;
            dirPath = Path.Combine(dirPath, "data");
            DirectoryInfo dir = new DirectoryInfo(dirPath);
            if (!Directory.Exists(dirPath))
            {
                dir = Directory.CreateDirectory(dirPath);
            }

            return dirPath;

        }

        public static string GetMysqlDump()
        {
            string s = ConfigurationManager.AppSettings["mysqlDumpPath"];
            if (string.IsNullOrEmpty(s))
            {
                return mysqlDump;
            }

            return s;
        }

        public static string GetSqlConnectionString()
        {
            string conn = "Server=localhost;Database=calemShop;Uid=root;Pwd=rroott;CharSet=utf8;Convert Zero Datetime=True";
            string s = ConfigurationManager.AppSettings["connectionString"];
            if (string.IsNullOrEmpty(s))
            {
                return conn;
            }

            return s;
        }

        public static string GetGlobalSqlConnectionString()
        {
            string conn = "Server=localhost;Database=calemShop;Uid=root;Pwd=rroott;CharSet=utf8;Convert Zero Datetime=True";
            string s = ConfigurationManager.AppSettings["globalConnectionString"];
            if (string.IsNullOrEmpty(s))
            {
                return conn;
            }

            return s;
        }

        public static string GetSoundCompletePath()
        {
            string root = Path.Combine(GetDataDir(), "sound");
            string soundName = "complete.wav";
            string s = ConfigurationManager.AppSettings["soundImportComplete"];
            if (string.IsNullOrEmpty(s))
            {
                return root = Path.Combine(root, soundName);
            }

            return root = Path.Combine(root, "complete.wav"); ;
        }

        public static string GetBranchId()
        {
            string defaultValue = "Branch01";
            string s = ConfigurationManager.AppSettings["branchId"];
            if (string.IsNullOrEmpty(s))
            {
                return defaultValue;
            }

            return s;
        }

        public static string GetBillTitle()
        {
            string defaultValue = "*** CÀ LEM ***";
            string s = ConfigurationManager.AppSettings["billTitle"];
            if (string.IsNullOrEmpty(s))
            {
                return defaultValue;
            }

            return string.Format("*** {0} ***", s);
        }

        public static string GetBillHeader()
        {
            string defaultValue = "THỜI TRANG TRẺ EM";
            string s = ConfigurationManager.AppSettings["billHeader"];
            if (string.IsNullOrEmpty(s))
            {
                return defaultValue;
            }

            return s;
        }


        public static string GetBillHotline()
        {
            string defaultValue = "0616 549 945";
            string s = ConfigurationManager.AppSettings["billHotline"];
            if (string.IsNullOrEmpty(s))
            {
                return defaultValue;
            }

            return s;
        }

        public static string GetBillURL()
        {
            string defaultValue = "www.facebook.com/Baby.Kutee.Shop";
            string s = ConfigurationManager.AppSettings["billUrl"];
            if (string.IsNullOrEmpty(s))
            {
                return defaultValue;
            }

            return s;
        }

        public static string GetBillHomeAddress()
        {
            string defaultValue = "197 Phan Đình Phùng P.Thanh Bình TP.Biên Hòa";
            string s = ConfigurationManager.AppSettings["billHomeAddress"];
            if (string.IsNullOrEmpty(s))
            {
                return defaultValue;
            }

            return s;
        }

        public static string GetBillCity()
        {
            string defaultValue = "TP.Biên Hòa";
            string s = ConfigurationManager.AppSettings["billCityName"];
            if (string.IsNullOrEmpty(s))
            {
                return defaultValue;
            }

            return s;
        }

        public static string GetShopTitle()
        {
            string title = "Hệ thống Calem shop";
            string s = ConfigurationManager.AppSettings["shopTitle"];
            if (string.IsNullOrEmpty(s))
            {
                return title;
            }

            return s;
        }


        public static string GetPrinterBillName()
        {
            string title = "EPSON";
            string s = ConfigurationManager.AppSettings["printerBill"];
            if (string.IsNullOrEmpty(s))
            {
                return title;
            }

            return s;
        }

        public static string GetPrinterName()
        {
            string title = "CANON";
            string s = ConfigurationManager.AppSettings["printerDoc"];
            if (string.IsNullOrEmpty(s))
            {
                return title;
            }

            return s;
        }


        public static string[] GetCalemBranchList()
        {
            string title = "Calem I";
            string s = ConfigurationManager.AppSettings["branchList"];
            if (string.IsNullOrEmpty(s))
            {
                return new string[] { title };
            }

            string[] list = s.Split(',');
            return list;
        }


        public static string GetDBBranchConnection(string branchName)
        {
            string key = branchName + "_DBConnection";
            string s = ConfigurationManager.AppSettings[key];
            if (string.IsNullOrEmpty(s))
            {
                return null;
            }


            return s;
        }
    }
}
